import 'package:flutter/material.dart';

/**
 * 计数器练习，StatefulWidget
 */
void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('商品列表'),
      ),
      body: MyHomeContent(),
    );
  }
}

class MyHomeContent extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MyState();
  }

}

class _MyState extends State<MyHomeContent>{
  int _count = 0;

  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Row(
            children: <Widget>[
              RaisedButton(
                onPressed: ()=>{setState(()=>{_count++})},
                child: Icon(Icons.add,color: Colors.white,size: 30,),
                color: Colors.red,
              ),
              SizedBox(width: 10,),
              RaisedButton(
                  onPressed: ()=>{setState(()=>{_count--})},
                  child: Icon(Icons.remove,color: Colors.white,size: 30,),
                  color: Colors.green,
              ),
            ],
            mainAxisAlignment: MainAxisAlignment.center,
          ),
          Text('当前计数:$_count'),
        ],
      ),
    );
  }

}
